#include "Model2D.h"

Model2D::Model2D(void)
{
	init();
}


Model2D::~Model2D(void)
{
}

void Model2D::render()
{
	
	glPushMatrix();
	glTranslatef(posX,posY,0.0f);
	glRotatef(angle,0.0f,0.0f,1.0f);
	glColor3f(0.6,0.8,1.0);
	glBegin(GL_TRIANGLES);
		glVertex2d(Ax, Ay);
		glVertex2d(Bx, By);
		glVertex2d(Cx, Cy);
	glEnd();
	glPopMatrix();
}

void Model2D::rotate(float deltaAngle)
{
	if (angle+deltaAngle > 360.0f) {
		angle=angle+deltaAngle-360.0f;
	}
	else if (angle+deltaAngle < 0.0f) {
		angle=360+angle+deltaAngle;
	} else {
		angle+=deltaAngle;
	}
}

void Model2D::translate(float x, float y)
{
	posX+=x;
	posY+=y;
}

//Protected
void Model2D::init()
{
	Ax = 80.0f;
	Ay = 0.0f;
	Bx = 0.0f;
	By = 20.0f;
	Cx = 0.0f;
	Cy = -20.0f;

	posX = 200.0f;
	posY = 200.0f;
	angle = 0.0f;
}
